package com.ssm.hj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.hj.search.GroupClassificationSearch;
import com.ssm.hj.service.GroupClassificationService;
import com.ssm.hj.view.GroupClassificationView;
import com.ssm.mapper.GroupClassificationMapper;
import com.ssm.pojo.GroupClassification;
import com.ssm.pojo.TExamination;
import com.ssm.pojo.Tjsc;
import com.ssm.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GroupClassificationServiceImpl implements GroupClassificationService {
    @Resource
    private GroupClassificationMapper groupClassificationMapper;
    @Override
    public PageInfo<GroupClassificationView> queryGroupClassificationAllService(Page<GroupClassificationSearch> page) throws Exception {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        return new PageInfo<GroupClassificationView>(this.groupClassificationMapper.queryGroupClassificationAll(page.getSearchObj()));
    }

    @Override
    public GroupClassificationView queryByFileNumberService(Page<Integer> page) throws Exception {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        PageInfo<Tjsc> pageInfo =new PageInfo<Tjsc>(this.groupClassificationMapper.queryByIdTest(page.getSearchObj()));
        GroupClassificationView groupClassificationView = this.groupClassificationMapper.queryByFileNumber(page.getSearchObj());
        groupClassificationView.setPageInfo(pageInfo);
        return groupClassificationView;
    }

    @Override
    public List<User> queryHealthManagerService() throws Exception {
        return this.groupClassificationMapper.queryHealthManager();
    }

    @Override
    public int addOrUpdateGroupClassificationService(GroupClassification groupClassification) throws Exception {
        int i = this.groupClassificationMapper.queryGroupClassificationById(groupClassification.getRid());
        System.out.println(i);
        if(i>0){
            return this.groupClassificationMapper.updateGroupClassification(groupClassification);
        }else{
            return this.groupClassificationMapper.saveGroupClassification(groupClassification);
        }
    }

    @Override
    public List<TExamination> queryTExaminationByIdService(int id) throws Exception {
        return this.groupClassificationMapper.queryTExaminationById(id);
    }
}
